/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"470A9C1D-63DB-461F-BD4A-D49A9FB2D7CB"}
 */
var fFormLlama = 'recepciones_carga_cab';

/**
 * Handle changed data.
 *
 * @param {Object} oldValue old value
 * @param {Object} newValue new value
 * @param {JSEvent} event the event that triggered the action
 *
 * @returns {Boolean}
 *
 * @properties={typeid:24,uuid:"508A919D-81B7-4EE5-AB24-5A79D8D744D8"}
 */
function onDataChangeRemito(oldValue, newValue, event) {
	var query 	= 'select rem_cabecera_id from rem_cabecera where cliente_id = ? and nro_remito = ? and userv_id = ?'
	var args 	= new Array(forms[fFormLlama].cliente_id, remito, globals.gUservID)
	var ds 		= databaseManager.getDataSetByQuery('infocom',query,args,1)
	
	if (ds.getMaxRowIndex() == 0)
	{
		globals.DIALOGS.showWarningDialog('Aviso','El remito no existe para ese cliente','OK')
		return false
	}
	onRecordSelection()
	return true
}

/**
 * Handle changed data.
 *
 * @param {Object} oldValue old value
 * @param {Object} newValue new value
 * @param {JSEvent} event the event that triggered the action
 *
 * @returns {Boolean}
 *
 * @properties={typeid:24,uuid:"12272E50-1E0D-48CA-A3BB-36BA27E3CC35"}
 */
function onDataChangeCantidad(oldValue, newValue, event) {
	if (newValue > recep_detalle_to_rem_detalle.cantidad)
	{
		globals.DIALOGS.showWarningDialog('Aviso','La cantidad es mayor a la del remito','OK')
		return false
	}
	cantidad_alter = newValue
	return true
}

/**
 * Handle changed data.
 *
 * @param {Object} oldValue old value
 * @param {Object} newValue new value
 * @param {JSEvent} event the event that triggered the action
 *
 * @returns {Boolean}
 *
 * @properties={typeid:24,uuid:"5FA57D6F-2C42-49D7-BF3A-50BF14D42D00"}
 */
function onDataChangeDetalle(oldValue, newValue, event) {
	cantidad 		= recep_detalle_to_rem_detalle.cantidad_pendiente_fac
	cod_producto 	= utils.stringTrim(recep_detalle_to_rem_detalle.cod_producto)
	producto_id 	= recep_detalle_to_rem_detalle.producto_id
	precio_unitario	= recep_detalle_to_rem_detalle.precio_unitario
	return true
}

/**
 * Handle record selected.
 *
 * @param {JSEvent} [event] the event that triggered the action
 *
 * @properties={typeid:24,uuid:"AE89F3DA-7447-4177-AAA8-AA4DCBA00325"}
 */
function onRecordSelection(event) {
	if (remito != null)
	{
		var query = 'SELECT texto + " - " + cantidad_pendiente_fac, rem_detalle_id FROM rem_detalle where rem_cabecera_id = ?'
		var args = [recep_detalle_to_rem_cabecera.rem_cabecera_id]
		var ds = databaseManager.getDataSetByQuery('infocom',query,args,-1)
		
		application.setValueListItems('recepciones_remito_detalle',ds)	
	}
}
